package com.aurora.config;

import com.aurora.model.vo.rabbitMQ.*;
import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import static com.aurora.constant.MQPrefixConst.*;

/**
 * @author 刘橙七
 * rabbitmq的配置类
 */
@Configuration
public class RabbitMQConfig {

    /**
     * 发布订阅模式交换机
     */
    @Bean
    public FanoutExchange fanoutExchange() {
        return new FanoutExchange(FANOUT_EXCHANGE);
    }

    /**
     * 发布订阅模式匿名队列1
     */
    @Bean
    public Queue fanoutQueue1() {
        return new AnonymousQueue();
    }

    /**
     * 发布订阅模式匿名队列2
     */
    @Bean
    public Queue fanoutQueue2() {
        return new AnonymousQueue();
    }

    /**
     * 将两个匿名队列绑定到交换机上
     */
    @Bean
    public Binding binding1(FanoutExchange fanoutExchange, Queue fanoutQueue1) {
        return BindingBuilder.bind(fanoutQueue1).to(fanoutExchange);
    }

    @Bean
    public Binding binding2(FanoutExchange fanoutExchange, Queue fanoutQueue2) {
        return BindingBuilder.bind(fanoutQueue2).to(fanoutExchange);
    }

    @Bean
    public FanoutReceiver fanoutReceiver() {
        return new FanoutReceiver();
    }

    @Bean
    public FanoutSender fanoutSender() {
        return new FanoutSender();
    }


    /**
     * 工作模式
     */
    @Bean
    public Queue workQueue() {
        return new Queue(WORK_QUEUE);
    }

    @Bean
    public WorkReceiver workReceiver1() {
        return new WorkReceiver(1);
    }

    @Bean
    public WorkReceiver workReceiver2() {
        return new WorkReceiver(2);
    }

    @Bean
    public WorkSender workSender() {
        return new WorkSender();
    }


    /**
     * 第一个队列
     */
    @Bean
    public Queue firstQueue() {
        return new Queue(FIRST_QUEUE);
    }

    /**
     * 第一个队列的生产者
     */
    @Bean
    public SimpleSender firstProducer() {
        return new SimpleSender();
    }

    /**
     * 启动前 必须实例化消息生产者
     */
    @Bean
    public SimpleReceiver secondQueue() {
        return new SimpleReceiver();
    }

    /**
     * 启动前 必须实例化消息消费者
     */
    @Bean
    public Queue articleQueue() {
        return new Queue(MAXWELL_QUEUE, true);
    }

    @Bean
    public FanoutExchange maxWellExchange() {
        return new FanoutExchange(MAXWELL_EXCHANGE, true, false);
    }

    @Bean
    public Binding bindingArticleDirect() {
        return BindingBuilder.bind(articleQueue()).to(maxWellExchange());
    }

    @Bean
    public Queue emailQueue() {
        return new Queue(EMAIL_QUEUE, true);
    }

    @Bean
    public FanoutExchange emailExchange() {
        return new FanoutExchange(EMAIL_EXCHANGE, true, false);
    }

    @Bean
    public Binding bindingEmailDirect() {
        return BindingBuilder.bind(emailQueue()).to(emailExchange());
    }

    @Bean
    public Queue subscribeQueue() {
        return new Queue(SUBSCRIBE_QUEUE, true);
    }

    @Bean
    public FanoutExchange subscribeExchange() {
        return new FanoutExchange(SUBSCRIBE_EXCHANGE, true, false);
    }

    @Bean
    public Binding bindingSubscribeDirect() {
        return BindingBuilder.bind(subscribeQueue()).to(subscribeExchange());
    }
}
